import 'package:flutter/material.dart';
import 'package:flutter_common/util/string_utils.dart';
import 'package:fluttertoast/fluttertoast.dart';

export 'package:fluttertoast/fluttertoast.dart';
import 'context_extension.dart';

class ToastUtil {

  ///toast提示
  static bool toast(bool isError, String errorMsg) {
    if (isError) {
      errorToast(errorMsg);
    }
    return isError;
  }

  static bool emptyToast(String? content, String toast) {
    if(content.isNullOrEmpty){
      showToast(toast);
      return true;
    }
    return false;
  }

  ///toast提示
  static void showToast(String content,{ToastGravity gravity = ToastGravity.CENTER, Toast? toastLength}) {
    Fluttertoast.cancel();
    Fluttertoast.showToast(
        msg: content,
        toastLength: toastLength,
        gravity: gravity,
        backgroundColor: const Color(0x7f000000));
  }

  ///toast提示
  static void errorToast(String content, [ToastGravity gravity = ToastGravity.CENTER]) {
    Fluttertoast.cancel();
    Fluttertoast.showToast(
        msg: content,
        gravity: gravity,
        textColor: const Color(0xffEE0A24),
        backgroundColor: const Color(0xfffdeaed));
  }

  ///toast提示
  static void successToast(String content, [ToastGravity gravity = ToastGravity.CENTER]) {
    Fluttertoast.cancel();
    Fluttertoast.showToast(
        msg: content,
        gravity: gravity,
        textColor: const Color(0xff07C160),
        backgroundColor: const Color(0xffeaf9f1));
  }

  ///旋转 toast提示
  static void showRotateToast(BuildContext context, String msg, {bool rotate = false}) {
    Widget contentView = Container(
      decoration: const BoxDecoration(
          color: Colors.black,
          borderRadius: BorderRadius.all(Radius.circular(12))),
      padding: const EdgeInsets.only(left: 24, right: 24, bottom: 12, top: 12),
      child: Text(
        msg,
        style: TextStyle(
            color: Colors.white,
            fontWeight: FontWeight.normal,
            fontSize: fontSize30),
      ),
    );
    final fToast = FToast().init(context);
    fToast.showToast(
        gravity: ToastGravity.CENTER,
        child: RotatedBox(quarterTurns: rotate ? 1 : 0, child: contentView));
  }
}